package org.niit.common

import org.apache.spark.{SPARK_BRANCH, SparkConf}
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.catalyst.expressions.Second
import org.apache.spark.streaming.Seconds
import org.niit.util.SparkUtil

// 通用代码块（需要时继承）
trait TApp extends App {  //

  var spark: SparkSession = _  //

  def start(master: String = "local[*]", appName: String = "Application")(op : => Unit):Unit ={
    val sparkConf = new SparkConf().setMaster(master).setAppName(appName)
    val sc = SparkUtil.CreateSpark(sparkConf, Seconds(5))

    val spark = SparkUtil.takeSpark()  //

    val ssc = SparkUtil.takeSSC()

    sc.setLogLevel("ERROR")

    try {
      op
    }catch {
      case e: Exception => e.printStackTrace()
    }
  }

}
